/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.Jogo;

import Biblioteca.VerificaErros;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;

/**
 *
 * @author Igor
 */
public class FramePanelTrocaFaseSubFase extends javax.swing.JPanel {

    //Atributos
    private FrameJogo frameJogo;

    /**
     * Creates new form FramePanelTrocaFaseSubFase
     */
    public FramePanelTrocaFaseSubFase(FrameJogo frameJogo, long percAcerto) {
        initComponents();
        this.frameJogo = frameJogo;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelPercentualAcerto = new javax.swing.JLabel();
        buttonIniciarFaseJogo = new javax.swing.JButton();
        labelEstrela1 = new javax.swing.JLabel();
        labelEstrela2 = new javax.swing.JLabel();
        labelEstrela3 = new javax.swing.JLabel();

        labelPercentualAcerto.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        labelPercentualAcerto.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelPercentualAcerto.setText("Seu percentual de acerto foi: 0%");

        buttonIniciarFaseJogo.setText("Iniciar Fase do Jogo");
        buttonIniciarFaseJogo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonIniciarFaseJogoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelPercentualAcerto, javax.swing.GroupLayout.PREFERRED_SIZE, 573, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(76, 76, 76)
                        .addComponent(buttonIniciarFaseJogo, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(labelEstrela1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelEstrela2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelEstrela3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(136, 136, 136))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelPercentualAcerto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonIniciarFaseJogo, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(labelEstrela3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelEstrela2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelEstrela1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void buttonIniciarFaseJogoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonIniciarFaseJogoActionPerformed
        // TODO add your handling code here:
        try {
            this.frameJogo.ativarPanelJogo();
            this.frameJogo.getJogo().iniciaFaseSubFase(false);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, VerificaErros.retornaMensagemErro(e), "Erro!", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_buttonIniciarFaseJogoActionPerformed

    public void mostrarPanelTrocaFaseSubFase(long percAcerto) {
        String dirImagem = "./banco_de_dados/imagens_sistema/";

        //gambiarra
        labelPercentualAcerto.setText("Seu percentual de acerto foi: " + percAcerto + "%");
        labelPercentualAcerto.setHorizontalAlignment(SwingConstants.CENTER);

        labelEstrela1.setIcon(null);
        labelEstrela2.setIcon(null);
        labelEstrela3.setIcon(null);
        if (this.frameJogo.getJogo() != null && this.frameJogo.getJogo().getModoJogo() > 2) {
            ImageIcon ig = new ImageIcon(dirImagem + "estrelaCinza.png");
            //Amplia a imagem fazendo-a ocupar todo o JLabel
            labelEstrela1.setIcon(new ImageIcon(ig.getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT)));
            labelEstrela2.setIcon(new ImageIcon(ig.getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT)));
            labelEstrela3.setIcon(new ImageIcon(ig.getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT)));

            ig = new ImageIcon(dirImagem + "estrelaAmarela.png");
            if (percAcerto >= 0 && percAcerto <= 100) {
                labelEstrela1.setIcon(new ImageIcon(ig.getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT)));
            }
            if (percAcerto >= 34 && percAcerto <= 100) {
                labelEstrela2.setIcon(new ImageIcon(ig.getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT)));
            }
            if (percAcerto >= 67 && percAcerto <= 100) {
                labelEstrela3.setIcon(new ImageIcon(ig.getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT)));
            }
            labelEstrela1.repaint();
            labelEstrela2.repaint();
            labelEstrela3.repaint();
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonIniciarFaseJogo;
    private javax.swing.JLabel labelEstrela1;
    private javax.swing.JLabel labelEstrela2;
    private javax.swing.JLabel labelEstrela3;
    private javax.swing.JLabel labelPercentualAcerto;
    // End of variables declaration//GEN-END:variables
}
